#include "scr_game_state_manager.h"
#include "scr_game.h"
#include "scr_game_state.h"

SCRGameStateManager::SCRGameStateManager()
{
}

SCRGameStateManager::~SCRGameStateManager()
{
	m_StateStack = std::stack<SCRGameStatePtr>();
	m_StateQueue = std::queue<SCRGameStatePtr>();
}

SCRGameStatePtr SCRGameStateManager::IsRunning(const int& Delta)
{
	SCRGameStatePtr GameState;
	
	if (m_StateStack.size() > 0)
	{
		GameState = m_StateStack.top();;
		GameState->OnUpdate(Delta);
		GameState->OnRender(Delta);
	}

	return GameState;
}

void SCRGameStateManager::ClearQueue()
{
	while (m_StateQueue.size() > 0)
	{
		SCRGameStatePtr Front = m_StateQueue.front();
		Front->OnTerminate();
		m_StateQueue.pop();
	}
}

void SCRGameStateManager::Pop()
{
	if (m_StateStack.size() > 0)
	{
		SCRGameStatePtr Top = m_StateStack.top();
		m_StateQueue.push(Top);
		m_StateStack.pop();
	}
}

void SCRGameStateManager::Push(SCRGameState* pState)
{
	if (pState)
	{
		pState->OnInitialize();
		m_StateStack.push(SCRGameStatePtr(pState));
	}
}
